using System;
using System.Net;
using System.Text;
namespace 阿里妈妈登录
{
	public class AlimamaSvc
	{
		public static bool checkAlimamaLogin()
		{
			return AlimamaSvc.checkAlimamaLogin(GetCookie.GetCookieString("http://www.alimama.com"));
		}
		public static bool checkAlimamaLogin(string cookie)
		{
			bool result;
			try
			{
				string format = "http://pub.alimama.com/common/getUnionPubContextInfo.json";
				string address = string.Format(format, "ABC");
				WebClient webClient = new WebClient();
				webClient.Headers.Add("Accept", "application/json, text/javascript, */*; q=0.01");
				webClient.Headers.Add("X-Requested-With", "XMLHttpRequest");
				webClient.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36");
				webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
				webClient.Headers.Add("Referer", "http://pub.alimama.com/myunion.htm");
				webClient.Headers.Add("Accept-Encoding", "gzip,deflate,sdch");
				webClient.Headers.Add("Accept-Language", "zh-CN,zh;q=0.8");
				webClient.Headers.Add("Cookie", cookie);
				byte[] array = webClient.DownloadData(address);
				string value = webClient.ResponseHeaders["Content-Encoding"];
				string text;
				if ("gzip".Equals(value))
				{
					text = CUtil.parseHtmlGzip(array, Encoding.UTF8);
				}
				else
				{
					text = Encoding.UTF8.GetString(array);
				}
				if (text.Contains("\"message\":\"nologin\"") || text.Contains("status") || text.Contains("wait"))
				{
					result = false;
				}
				else
				{
					if (text.Contains("\"nologin\"") || text.Contains("\"noLogin\""))
					{
						result = false;
					}
					else
					{
						result = true;
					}
				}
			}
			catch
			{
				result = false;
			}
			return result;
		}
	}
}
